/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    bool isSymmetric(TreeNode* root) {
        return root==nullptr?true:recur(root->left,root->right);
    }

    bool recur(TreeNode* left,TreeNode* right)
    {
        //遍历到同时左右子树为空则前面都对称，返回true
        if(left==nullptr&&right==nullptr)return true;
        //若只有一个到达空结点则说明不对称，或者当前结点值不相同
        if(left==nullptr||right==nullptr||left->val!=right->val)return false;

        //往下遍历
        return recur(left->left,right->right)&&recur(left->right,right->left);
    }
};